package com.wushixin.springdemo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wushixin.springdemo.dao.UserDao;
import com.wushixin.springdemo.pojo.User;
import com.wushixin.springdemo.service.UserService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserDao,User> implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public Boolean check(User user) {
        LambdaQueryWrapper<User> lambdaQuery = new LambdaQueryWrapper<>();
        lambdaQuery.eq(Strings.isNotEmpty(user.getName()), User::getName, user.getName());
        lambdaQuery.eq(Strings.isNotEmpty(user.getPwd()),User::getPwd,user.getPwd());
        User user1 = userDao.selectOne(lambdaQuery);
        System.out.println("user ============== " + user1);

        return userDao.selectOne(lambdaQuery) != null ? true:false ;
    }

    @Override
    public Page<User> getPage(int current, int pageSize) {

        Page<User> page = new Page<>(current,pageSize);
        userDao.selectPage(page,null);

        return page;
    }
    @Override
    public Page<User> getPage(int current, int pageSize, User student) {
        String name = student.getName();
        String pwd = student.getPwd();
        Integer state = student.getState();
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<User>();
        lambdaQueryWrapper.like(name!=null,User::getName,name);
        lambdaQueryWrapper.like(pwd!=null,User::getPwd,pwd);
        lambdaQueryWrapper.like(state!=null,User::getState,state);
        Page<User> page = new Page<>(current,pageSize);
        Page<User> userPage = userDao.selectPage(page, lambdaQueryWrapper);
        return page;
    }

//    @Override
//    public List<UserDao> limit(String name) {
//
//        LambdaQueryWrapper<UserDao> lqw = new LambdaQueryWrapper<UserDao>();
//        lqw.like(name!=null,User::getName,name);
//
//        return userDao.selectList(lqw);
//    }


}
